﻿using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Ruminate.Utils;

namespace Ruminate.GUI.Framework {

    /// <summary>
    /// A component responsible for specifying the location of an object.
    /// </summary>
    public abstract class LocationComponent {

        /// <summary>
        /// Set in the constructor of the Element class. All components should 
        /// follow this practice.
        /// </summary>
        internal protected Element LinkedElement;

        #region Exposed Data

        /// <summary>
        /// Location offset from parents
        /// </summary>
        public abstract Vector2 Location { get; set; }
        public abstract Vector2 Size { get; set; }

        /// <summary>
        /// Absolute location in pixels from top left of window
        /// </summary>
        public abstract Vector2 RenderLocation { get; }
        public abstract Rectangle RenderBounds { get; }

        /// <summary>
        /// Absolute location for visible area on screen
        /// </summary>
        public abstract Vector2 RenderSafeAreaLocation { get; }
        public abstract Rectangle RenderSafeArea { get; }

        /// <summary>
        /// Amount in pixels any child elements should be moved
        /// </summary>
        public abstract Vector2 ChildOffset { get; set; }

        #endregion             
        
        /// <summary>
        /// Align current element to the viewport
        /// </summary>
        /// <param name="graphicsDevice"></param>
        internal protected abstract void AlignToViewport(GraphicsDevice graphicsDevice);

        /// <summary>
        /// Align current element to the parent element
        /// </summary>
        internal protected abstract void AlignToParentElement();

        /// <summary>
        /// Visible representation of RenderBounds and RenderSafeArea for debugging.
        /// </summary>
        [Conditional("LAYOUT")]
        internal void DrawDebug() {
            //LinkedElement.InstanceData.GuiBatch.Draw(
                //DebugUtils.White,
                //RenderBounds,
                //Color.LightBlue);
            LinkedElement.InstanceData.GuiBatch.Draw(
                DebugUtils.White,
                RenderSafeArea,
                Color.LightGreen);
        }
    }
}
